<?php
require_once '../../includes/global.php';




//得到配置文件
$wcfg=Dga('wcfg',"web like '".$sitename."' and lg like '".$_SESSION[LG]."'");
$wcfg=json_decode($wcfg[wcfg],true);

$webconfig[lgconfig]=$wcfg['lang'];
$webconfig[num]=$wcfg['num'];

$sortinfo=Dga('infosort'," id = '".$_POST[sortid]."'");
$zd="abcdefghijklmnopqrstuvwxyz";
 foreach($webconfig[lgconfig] as $lg =>$key){
 
 //pic相关操作 
	if($_FILES[$lg]['name']['pic']!=""){
	$time=time();
	$otype=substr(strtolower($_FILES[$lg]['name']['pic']),-3);
	//echo $otype;
	$xiantype=array('php','.js','asp','jsp','htm','tml','inc');
	$suoluetype=array('jpg','gif','png');
	in_array($otype,$xiantype)&&Jt("../logout.php",'越权操作');
	$_FILES[$lg]['size']['pic']>0&&$_FILES[$lg]['size']['pic']>500000&&Jt($_SERVER['HTTP_REFERER'],'图片太大');
	$filename="../../uploads/pic/".$lg.$_POST[gid].".".$otype;
	@unlink($filename);
	$copymes=copy($_FILES[$lg]['tmp_name']['pic'] ,$filename);
in_array($otype,$suoluetype)&&createthumb($_FILES[$lg]['tmp_name']['pic'],".".$otype,$lg.$_POST[gid]);
	$_POST[$lg][pic]=$lg.$_POST[gid].".".$otype;
	}
	//files操作
	if($_FILES[$lg]['name']['files']!="")
	{
		$xiantype=array('mp3','wma','jpg','gif','png','zip','rar');
		$uploaddir=$_SERVER['DOCUMENT_ROOT']."uploads/files/";
		$_FILES[$lg]['size']['files']>0&&$_FILES[$lg]['size']['files']>20000000&&Jt($_SERVER['HTTP_REFERER'],'文件太大');		$otype=substr(strtolower($_FILES[$lg]['name']['files']),-3);
		//print_r($otype);exit;
		!in_array($otype,$xiantype)&&Jt($_SERVER['HTTP_REFERER'],'文件格式不正确');

		if(!file_exists($uploaddir.date("Ymd")))//生成日期目录
			{
				@mkdir($uploaddir.date("Ymd"),0777);
			}
		$filenames=floor(Bic());
		$filedir=$uploaddir.date("Ymd").'/'.$filenames.".".$otype;//设置文件名
		@unlink($filedir);
		copy($_FILES[$lg]['tmp_name']['files'],$filedir);
		chmod($filedir, 0777);//设定上传的文件的属
		$_POST[$lg][files]="/uploads/files/".date("Ymd")."/".$filenames.".".$otype;
		//print_r($_POST[$lg][files]);exit;
	}

//相关时间 主ubb userid的设定过滤
$_POST[$lg][sortid]=$_POST[sortid];
$_POST[$lg][gid]=$_POST[gid];
$_POST[$lg][bdid]=$_POST[bdid];
$_POST[$lg][bdsortid]=$_POST[bdsortid];
$_POST[$lg][lg]=$lg;
$_POST[$lg][adddate]=time();
$_POST[$lg][content]= stripslashes($_POST[$lg][content]);
$_POST[$lg][userid]=$_SESSION[userinfo][username];
//整合checkbox;	
	for($ii=13;$ii<26;$ii++)
	{
	  $uu=substr($zd,$ii,1);
	 $_POST[$lg]['a'.$uu]=implode(",",$_POST[$lg]['a'.$uu]);
	}
//整合file文件;	  

 for($ii=25;$ii<26;$ii++)
	{
	  $uu=substr($zd,$ii,1);
	   if(isset($_POST[$lg]['c'.$uu])){
 
			$sortinfo1['c'.$uu]=unserialize($sortinfo['c'.$uu]);
			foreach($sortinfo1['c'.$uu] as $key =>$value)
			{
			$sortinfo1['c'.$uu][$key]=stripslashes($value);
			}
			Fw($sortinfo1['c'.$uu]['lujing'],html_entity_decode(stripslashes($_POST[$lg]['c'.$uu])));
	  }
	}
	
  for($ii=23;$ii<24;$ii++)
	{
	  $uu=substr($zd,$ii,1);
	   if(isset($_POST[$lg]['c'.$uu])){
 
			$sortinfo1['c'.$uu]=unserialize($sortinfo['c'.$uu]);
			foreach($sortinfo1['c'.$uu] as $key =>$value)
			{
			$sortinfo1['c'.$uu][$key]=stripslashes($value);
			}
			//echo $sortinfo1['c'.$uu]['lujing'];
			//echo $_POST[$lg]['c'.$uu];
			$_POST[$lg]['c'.$uu]!=''&&Fw($sortinfo1['c'.$uu]['lujing'],html_entity_decode(stripslashes($_POST[$lg]['c'.$uu])));
	  }
	}

	  for($ii=24;$ii<25;$ii++)
	{
	  $uu=substr($zd,$ii,1);
	   if(isset($_POST[$lg]['c'.$uu])){
 
			$sortinfo1['c'.$uu]=unserialize($sortinfo['c'.$uu]);
			foreach($sortinfo1['c'.$uu] as $key =>$value)
			{
			$sortinfo1['c'.$uu][$key]=stripslashes($value);
			}
			Fw($sortinfo1['c'.$uu]['lujing'].$lg.".php",html_entity_decode(stripslashes($_POST[$lg]['c'.$uu])));
	  }
	}
	
	
	//sort_binding
		for($ii=0;$ii<6;$ii++)	{
	  $uu=substr($zd,$ii,1);
	   if(isset($_POST[$lg]['d'.$uu])){
 
			$sortinfo1['d'.$uu]=unserialize($sortinfo['d'.$uu]);
			foreach($sortinfo1['d'.$uu] as $key =>$value)
			{
			$sortinfo1['d'.$uu][$key]=stripslashes($value);
			}

			if($sortinfo1['d'.$uu][dx]=='1'){
			 $_POST[$lg]['d'.$uu]=implode(",",$_POST[$lg]['d'.$uu]);
			}

	  }
	}

	//sh
		/*	
	   if(isset($_POST[$lg]['shno'])){
	   if(Sf(',',$_POST[$lg]['shno'])){
 			$_POST[$lg]['shuser']=substr($_POST[$lg]['shno'],0,strpos($_POST[$lg]['shno'],','));
			$_POST[$lg]['shno']=substr($_POST[$lg]['shno'],strpos($_POST[$lg]['shno'],',')+1);
			}else{
 			$_POST[$lg]['shuser']=$_POST[$lg]['shno'];
			$_POST[$lg]['shno']='';
			}//Jc($_POST);

		}
			*/
			
	   if(isset($sortinfo1['sh'])){
	   if(Sf('#',$_POST[$lg]['shno'])){
 			$_POST[$lg]['shuser']=substr($sortinfo1['sh'],0,strpos($sortinfo1['sh'],'#'));
			$_POST[$lg]['shno']=substr($sortinfo1['sh'],strpos($sortinfo1['sh'],'#')+1);
			}else{
 			$_POST[$lg]['shuser']=$_POST[$lg]['shno'];
			$_POST[$lg]['shno']='';
			}//Jc($_POST);

		}


	//操作数据库
	if($_POST[op]=='add'){
	unset($_POST[$lg][id]);
	Di($_POST[tname],$_POST[$lg]);
		$id = $db->last_insert_id();
	Du($_POST[tname],$ar,'id',$id);

	}
	else{
		if($_POST[$lg][id]==''){
		unset($_POST[$lg][id]);
		Di($_POST[tname],$_POST[$lg]);
		
		}else{
		Du($_POST[tname],$_POST[$lg],'id',$_POST[$lg][id]);
		}
	}


}
//print_r($_POST);

//Jt($_SERVER['HTTP_REFERER'],"That's OK");
Jt("infolist.php?op=list&sortid=$_POST[sortid]&mid=$_POST[mid]&from=$_POST[from]&bdid=$_POST[bdid]&bdsortid=$_POST[bdsortid]",'添加成功');
	
	
?>